<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de"> 
	<head>
		<title>References</title>
		<style type="text/css">
			<!--
				body {
					font-family: Verdana, Arial, sans;
					font-size: 12px;
					background-image: url('images/desktop.gif');
					color: white;
				}
				
				h1 {
					font-size: 16px;
					font-weight: bold;
				}
			-->
		</style>
		<script type="text/javascript" src="./js/mootools-core-1.3-full-compat.js"></script>
		<script type="text/javascript">
			<!--
				function gup(name) {
					name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
					var regexS = "[\\?&]" + name + "=([^&#]*)";
					var regex = new RegExp(regexS);
					var results = regex.exec(window.location.href);
					if (results == null)
						return "";
					else
						return results[1];
				}

				window.addEvent('load', function() {
					var url = decodeURIComponent(gup('url'));
					var xpath = decodeURIComponent(gup('xpath'));
					var token = decodeURIComponent(gup('token'));
					var proxyUrl = window.location.href.substr(0, window.location.href.indexOf('/getReferences.html')) + '/proxy';
					
					$('url').innerHTML = url;
					
					new Request.JSON({url: './references', onSuccess: function(result){
						$('list').innerHTML = '';
						if (result.results == 0) {
							var li = document.createElement('li');
							li.appendChild(document.createTextNode('No references found.'));
							$('list').appendChild(li);
						}
					    for (var i=0; i<result.results; i++) {
					    	var refuri = result.rows[i].targetUri;
					    	var refxpath = result.rows[i].targetXpath;
					    	var myRating = result.rows[i].myRating;
					    	var tags = result.rows[i].tags;
					    	var owner = result.rows[i].ownerUsername;
					    	var targetRefType = result.rows[i].targetRefType;
					    	var title = refuri.substr(refuri.indexOf("://")+3);
					    	title = title.substr(0, title.indexOf("/"));
					    	
					    	if (targetRefType == 'websiteSection') {
						    	var li = document.createElement('li');
						    	var a = document.createElement('a');
						    	a.setAttribute('href', '#');
						    	a.setAttribute('title', refuri);
						    	a.onclick = function() {
						    		var openUrl = proxyUrl+'?url='+encodeURIComponent(refuri)+'&xpath='+encodeURIComponent(refxpath);
						    		window.open(openUrl, 'proxy-ref-win');
						    	};
						    	a.appendChild(document.createTextNode(title));
						    	li.appendChild(a);
						    	li.appendChild(document.createElement('br'));
						    	li.appendChild(document.createTextNode('My Rating: ' + (myRating > -1 ? myRating : 'unrated')));
						    	li.appendChild(document.createElement('br'));
						    	li.appendChild(document.createTextNode('Tags: ' + tags));
						    	li.appendChild(document.createElement('br'));
						    	li.appendChild(document.createTextNode('Owner: ' + owner));
						    	$('list').appendChild(li);
					    	}
					    }
					}}).get({'action': 'getReferencesWeb', 'uri': url, 'xpath': xpath, 'token': token});
	});
//-->
</script>
	</head>
	<body>
		<div>
			<h1>References</h1>
			Below is a list of references for URL:<br />
			<span id="url">Loading...</span><br />
			<ul id="list">
				<li>Loading...</li>
			</ul>
		</div>
	</body>
</html>